/**
 * TMP显示
 * */


//获取一条数据
function getOne(){
    if (code == '' || code == undefined) {
        msgPop({msg: '码值错误'});
        return
    }
    var formData = {
        code: code, h5code: h5code,
    };
    console.log(formData);
    $.ajax({
        type: 'post',
        url: apiDomain + 'one',
        data: formData,
        success: function (res) {
            console.log(res);
            if (res.code != 0) {
                msgPop({msg: res.msg});
                return
            }
            var d = res.data;
            var h = '', i;
            if (d.cover != '') {
                $('#showImgOut').html('<img src="' + d.cover + '" width="100%"/>');
            }
            $('#title').html(d.title);
            $('#show_code').html(d.show_code);
            $('#describe').html(d.detail);
            $('#visit_total').html(d.visit_total);
            var attrs = d.attrs;
            if (attrs.length > 0) {
                h = '';
                for (i = 0; i < attrs.length; i ++) {
                    h += '<tr>';
                    h += '<td class="tl">' + attrs[i].attr_name + '</td>';
                    h += '<td class="tr">' + attrs[i].attr_val + '</td>';
                    h += '</tr>';
                }
                $('#attrList').html(h);
            }
            if (d.ad != '') {
                $('#advert').html('<img src="' + d.ad.cover + '"/>');
                setTimeout(function(){
                    setAdUse({ad_id: d.ad.id, tmp_id: d.id});
                }, 3000);
            }
            //setTimeout(function(){
            //    appPop();
            //}, 3000);
        },
        error: function () {
            console.log('网络错误');
        }
    });
}


//广告设置
function setAdUse(e){
    var formData = {
        ad_id: e.ad_id, h5code: h5code,
        type: 1, id: e.tmp_id,
    };
    $.ajax({
        type: 'post',
        url: apiDomain + 'ad/read',
        data: formData,
        success: function (res) {
            console.log(res);
            //if (res.code != 0) {
            //    msgPop({msg: res.msg});
            //    return
            //}
        },
        error: function () {
            console.log('网络错误');
        }
    });
}


//小程序弹窗
function appPop(){
    var path = '/h5/toxcx.html';
    path += '?code=' + code;
    path += '&h5code=' + h5code;
    console.log(path);
    window.location.href = path;
}